package fun.scxsh.webproject.util;

import java.sql.*;

public class DBUtil {
    public static String url = "jdbc:mysql://localhost:3306/testdb?useSSL=false&characterEncoding=utf8";;
    public static String user = "root";
    public static String password = "root123";

    /**
     * 获取连接
     * @return
     * @throws SQLException
     */
    public static Connection getConn() throws SQLException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return DriverManager.getConnection(url, user, password);
    }

    /**
     * 关闭连接
     * @param conn
     */
    public static void close(Connection conn) {
        if(conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
